package MyArrayList1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class  Card{
    private int number;
    private char style;

    public Card(int number, char style) {
        this.number = number;
        this.style = style;
    }

    @Override
    public String toString() {
        return "[number=" + number +
                ", style=" + style+"]";
    }
}
public class PuKe {
    //卡牌的4中固定样式
    public static final char[]style={'♦','♣','♠','⚪'};
    //买一副牌(牌盒子)
    public static List<Card> buyCard(){
        List<Card> cards=new ArrayList<>();
        for (int i = 0; i <4; i++) {
            for (int j = 0; j < 13; j++) {
                //构造一张牌
                Card temp=new Card(j,style[i]);
                //放入牌盒
                cards.add(temp);
            }
        }
        return cards;
    }
    //打乱牌的顺序(洗牌)
    public static void washCards(List<Card> cards){
        Random random=new Random();
        for (int i = cards.size()-1;i>0; i--) {
            int j= random.nextInt(i);
            swap(cards,i,j);
        }
    }

    //交换两张牌的位置
    public static void swap(List<Card>cards,int i,int j){
        Card temp=cards.get(j);
        cards.set(j,cards.get(i));
        cards.set(i,temp);
    }
    //发牌操作(三个人轮流拿5张牌)
    public static List<List<Card>> getCards(List<Card> cards){
        List<List<Card>> person=new ArrayList<>();
        person.add(new ArrayList<Card>());
        person.add(new ArrayList<Card>());
        person.add(new ArrayList<Card>());

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                person.get(j).add(cards.remove(i));

            }
        }
        return person;
    }
    public static void main(String[] args) {
        List<Card> cards=buyCard();
        washCards(cards);
        //定义一个person表示玩家，每个玩家都有属于自己的一副牌(二维数组)
        //通过getCards()给每一个玩家发牌
        List<List<Card>> person=getCards(cards);
        //打印每个玩家得到的牌
        for (int i = 0; i < person.size(); i++) {
            System.out.println(person.get(i));
            System.out.println("-----------------------------------------");
        }
        //打印剩余的牌
        System.out.println(cards);
    }
}
